package com.zimi.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zimi.model.WfFormPlugins;
import com.zimi.service.WfFormPluginsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: lmc
 * @Date: 2019/3/27 10:34
 * @Description:
 */

@Api("流程模块")
@RestController
@RequestMapping("wf/form/plugins")
public class WfFormPluginsApi {

    @Autowired
    private WfFormPluginsService wfFormPluginsService;

    @PostMapping("list")
    @ApiOperation("查询所有")
    public Map getAll(WfFormPlugins wfFormPlugins) {
        Map returnMap = new HashMap();
        returnMap.put("OK", "OK");
        returnMap.put("code", "200");
        returnMap.put("rows", wfFormPluginsService.selectAll(wfFormPlugins));
        returnMap.put("List", wfFormPluginsService.selectAll(wfFormPlugins));
        return returnMap;
    }

    @PostMapping("volist")
    @ApiOperation("查询所有")
    public Map getVOAll(WfFormPlugins wfFormPlugins) {
        Map returnMap = new HashMap();
        returnMap.put("OK", "OK");
        returnMap.put("code", "200");
        returnMap.put("rows", wfFormPluginsService.selectVOAll(wfFormPlugins));
        returnMap.put("List", wfFormPluginsService.selectVOAll(wfFormPlugins));
        return returnMap;
    }

    @PostMapping("pageListVO")
    @ApiOperation("查询所有")
    public Map getVOPageList(WfFormPlugins wfFormPlugins) {
        PageHelper.startPage(wfFormPlugins.getPage(), wfFormPlugins.getLimit());
        List<WfFormPlugins> list = wfFormPluginsService.selectAll(wfFormPlugins);
        PageInfo<WfFormPlugins> pageInfo = new PageInfo<>(list);
        Map returnMap = new HashMap();
        returnMap.put("OK", "OK");
        returnMap.put("code", "200");
        returnMap.put("total", pageInfo.getTotal());
        returnMap.put("rows", list);
        return returnMap;
    }

    @PostMapping("selectById")
    @ApiOperation("根据Id查询信息")
    public WfFormPlugins selectByPrimaryKey(int id) {
        return wfFormPluginsService.selectByPrimaryKey(id);
    }

    @PostMapping("findVOById")
    @ApiOperation("根据Id查询信息")
    public Object findVOById(int id) {
        Map map = new HashMap();
        map.put("OK", "OK");
        map.put("code", "200");
        map.put("wfFormPluginsVO", wfFormPluginsService.selectVOById(id));
        return map;
    }

    @PostMapping("deleteById")
    @ApiOperation("根据Id删除")
    public boolean deleteByPrimaryKey(int id) {
        return wfFormPluginsService.deleteByPrimaryKey(id) > 0 ? true : false;
    }

    @PostMapping("insert")
    @ApiOperation("添加")
    public Map insert(WfFormPlugins wfFormPlugins) {
        Map returnMap = new HashMap();
        boolean flag = wfFormPluginsService.insertSelective(wfFormPlugins) > 0 ? true : false;
        ;
        if (flag) {
            returnMap.put("OK", "OK");
            returnMap.put("code", "200");
        } else {
            returnMap.put("OK", "error");
            returnMap.put("code", "400");
        }
        return returnMap;
    }

    @PostMapping("update")
    @ApiOperation("根据条件修改信息")
    public Map updateByPrimaryKey(WfFormPlugins wfFormPlugins) {
        Map returnMap = new HashMap();
        boolean flag = wfFormPluginsService.updateByPrimaryKeySelective(wfFormPlugins) > 0 ? true : false;
        ;
        if (flag) {
            returnMap.put("OK", "OK");
            returnMap.put("code", "200");
        } else {
            returnMap.put("OK", "error");
            returnMap.put("code", "400");
        }
        return returnMap;
    }

    @PostMapping("inputDbInfo")
    @ApiOperation("导入模块控件")
    public Map inputDbInfo(int moduleId) {
        Map returnMap = new HashMap();
        returnMap.put("msg", wfFormPluginsService.saveInputDbInfo(moduleId));
        returnMap.put("OK", "OK");
        returnMap.put("code", "200");
        return returnMap;
    }


    @PostMapping("moveUp")
    @ApiOperation("上移")
    public Map moveUp(int id) {
        Map returnMap = new HashMap();
        returnMap.put("msg", wfFormPluginsService.moveUp(id));
        returnMap.put("OK", "OK");
        returnMap.put("code", "200");
        return returnMap;
    }

    @PostMapping("moveDown")
    @ApiOperation("上移")
    public Map moveDown(int id) {
        Map returnMap = new HashMap();
        returnMap.put("msg", wfFormPluginsService.moveDown(id));
        returnMap.put("OK", "OK");
        returnMap.put("code", "200");
        return returnMap;
    }


}
